package com.ebt.m.data.bean;


import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.text.TextUtils;

import com.ebt.m.BR;


public class UserInfo extends BaseObservable {

    private int userId;
    private String userName;
    private String password;
    private String token;
    private CompanyInfo companyInfo;
    private int validateStatus;
    private String userPublicKey;
    private String userPrivateKey;
    private String bindName;
    private String bindType;
    private String eBaoAccount;
    private String email;
    private String phone;
    private String result;
    private CardInfo cardInfo;

    public UserInfo() {
        clearUserInfo();
    }

    public String getBindName() {
        return bindName;
    }

    public void setBindName(String bindName) {
        this.bindName = bindName;
    }

    public String getBindType() {
        return bindType;
    }

    public void setBindType(String bindType) {
        this.bindType = bindType;
    }

    public String geteBaoAccount() {
        return eBaoAccount;
    }

    public void seteBaoAccount(String eBaoAccount) {
        this.eBaoAccount = eBaoAccount;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getAccessToken() {
        return token;
    }

    public void setAccessToken(String accessToken) {
        this.token = accessToken;
    }

    public CardInfo getCardInfo() {
        return cardInfo;
    }

    public void setCardInfo(CardInfo cardInfo) {
        this.cardInfo = cardInfo;
    }

    /**
     * 清除用户信息
     */
    public void clearUserInfo() {
        setUserId(0);
        setPassword("");
        setUserName("");
        setPhone("");
        setAccessToken("");
        setCompanyInfo(null);
        setValidateStatus(0);
        setUserPublicKey("");
        setUserPrivateKey("");
        setBindName(null);
        setBindType(null);
        seteBaoAccount(null);
        setEmail(null);
        setPhone(null);
        setResult(null);
        setCardInfo(null);
    }

    public void set(UserInfo userInfo) {
        if (userInfo.getUserId() > 0) {
            setUserId(userInfo.getUserId());
        }
        if (!TextUtils.isEmpty(userInfo.getUserName())) {
            setUserName(userInfo.getUserName());
        }
        if (!TextUtils.isEmpty(userInfo.getPassword())) {
            setPassword(userInfo.getPassword());
        }
        if (!TextUtils.isEmpty(userInfo.getAccessToken())) {
            setAccessToken(userInfo.getAccessToken());
        }
        if (userInfo.getCompanyInfo() != null) {
            setCompanyInfo(userInfo.getCompanyInfo());
        }
        if (!TextUtils.isEmpty(userInfo.getPhone())) {
            setPhone(userInfo.getPhone());
        }
        if (!TextUtils.isEmpty(userInfo.getBindName())) {
            setBindName(userInfo.getBindName());
        }
        if (!TextUtils.isEmpty(userInfo.getBindType())) {
            setBindType(userInfo.getBindType());
        }

        if (userInfo.getCardInfo() != null) {
            setCardInfo(userInfo.getCardInfo());
        }

        setValidateStatus(userInfo.getValidateStatus());
    }

    public void setUserId(int identity) {
        userId = identity;
    }

    public int getUserId() {
        return userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public CompanyInfo getCompanyInfo() {
        return companyInfo;
    }

    public void setCompanyInfo(CompanyInfo companyInfo) {
        this.companyInfo = companyInfo;
    }

    @Bindable
    public int getValidateStatus() {
        return validateStatus;
    }

    public void setValidateStatus(int validateStatus) {
        this.validateStatus = validateStatus;
        notifyPropertyChanged(BR.validateStatus);
    }

    public String getUserPublicKey() {
        return userPublicKey;
    }

    public void setUserPublicKey(String userPublicKey) {
        this.userPublicKey = userPublicKey;
    }

    public String getUserPrivateKey() {
        return userPrivateKey;
    }

    public void setUserPrivateKey(String userPrivateKey) {
        this.userPrivateKey = userPrivateKey;
    }

    public boolean isLogined() {
        if (userId == 0 || TextUtils.isEmpty(getAccessToken())) {
            return false;
        } else {
            return true;
        }
    }

    public boolean isRegisterCompany() {
        return getValidateStatus() == 1 && this.companyInfo != null;
    }

    public static class CompanyInfo {
        private int companyID;
        private String logoUrl;
        private String companyName;
        private String miniLogoUrl;
        private int category;
        private String nameForZyj;

        public int getCategory() {
            return category;
        }

        public void setCategory(int category) {
            this.category = category;
        }

        public String getMiniLogoUrl() {
            return miniLogoUrl;
        }

        public void setMiniLogoUrl(String miniLogoUrl) {
            this.miniLogoUrl = miniLogoUrl;
        }

        public int getCompanyID() {
            return companyID;
        }

        public void setCompanyID(int companyID) {
            this.companyID = companyID;
        }

        public String getLogoUrl() {
            return logoUrl;
        }

        public void setLogoUrl(String logoUrl) {
            this.logoUrl = logoUrl;
        }

        public String getCompanyName() {
            return companyName;
        }

        public void setCompanyName(String companyName) {
            this.companyName = companyName;
        }

        public String getNameForZyj() {
            return nameForZyj;
        }

        public void setNameForZyj(String nameForZyj) {
            this.nameForZyj = nameForZyj;
        }

    }


}
